package servlet;

import bean.ScreeningSchedule;
import dao.impl.ScreeningScheduleDaoImpl;
import dao.impl.VideoHallDaoImpl;
import service.impl.MovieServiceImpl;
import util.DataTypeConversion;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;

@WebServlet("/admin/add_screeningSchedule")
public class addScreeningSchedule extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cinemaIdStr = request.getParameter("cinemaId");
        String movieIdStr = request.getParameter("movieId");
        String videoHallIdStr = request.getParameter("videoHallId");
   //     String priceStr = request.getParameter("price");
        //BigDecimal price = new BigDecimal(priceStr);
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");
       // String seatNumStr = request.getParameter("seatNum");
        System.out.println(cinemaIdStr);
        System.out.println(movieIdStr);
        System.out.println(videoHallIdStr);
       // System.out.println(priceStr);
        //System.out.println(seatNumStr);
        System.out.println(startTime);
        System.out.println(endTime);
        ScreeningSchedule screeningSchedule = new ScreeningSchedule();
        screeningSchedule.setMovie(new MovieServiceImpl().getMovieById(Integer.parseInt(movieIdStr)));
        screeningSchedule.setVideoHall(new VideoHallDaoImpl().getVideoById(Integer.parseInt(videoHallIdStr)));
        //screeningSchedule.setSeatNum(Integer.parseInt(seatNumStr));
        screeningSchedule.setEndTime(DataTypeConversion.modifyDateString(endTime));
        screeningSchedule.setStartTime(DataTypeConversion.modifyDateString(startTime));



        boolean success =  new ScreeningScheduleDaoImpl().addScreeningSchedule(screeningSchedule);
        if (success){
            request.setAttribute("message","添加成功");
            request.setAttribute("page","aindex.jsp");
            request.getRequestDispatcher("alert.jsp").forward(request,response);
        }else {
            request.setAttribute("message","添加失败");
            request.setAttribute("page","aindex.jsp");
            request.getRequestDispatcher("alert.jsp").forward(request,response);
        }
    }
}
